package com.suanfa.tianxun;

import java.util.Arrays;

/**
 * @author tianxun
 * @date 2023/12/13 16:39
 * @desc 选择排序
 */
public class SelectionSort {
    public static void main(String[] args) {
        int[] arr = {27, 700, 49, 33, 49, 11, 101, 1};
        test(arr);
    }

    private static void test(int[] arr) {
        for (int i = 0; i < arr.length-1; i++) {
            int minIndex = i;
            for (int j = i+1; j < arr.length; j++) {
                if(arr[minIndex]>arr[j]){
                    minIndex=j;
                }
            }
            int tmp = arr[i];
            arr[i] = arr[minIndex];
            arr[minIndex] = tmp;
        }
        System.out.println(Arrays.toString(arr));
    }
}
